<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::namespace('Api')->prefix('v1')->group(function () {
    // 登录
    Route::post('login', 'LoginController@login')->name('login')->middleware('login.log');
    // 注册
    Route::post('register', 'RegisterController@store')->name('register');

    // 需要认证的路由组
    Route::middleware('api.refresh')->group(function () {
        // 退出登录
        Route::post('logout', 'LoginController@logout')->name('logout');
        // 修改密码
        Route::put('password', 'PasswordController@update')->name('password.update');

        // 基础信息不做权限检查
        Route::get('users/params', 'UserController@params')->name('users.params');
        Route::get('roles/params', 'RoleController@params')->name('roles.params');
        Route::get('permissions/params', 'PermissionController@params')->name('permissions.params');
        Route::get('menus/params', 'MenuController@params')->name('menus.params');
        Route::get('plans/params', 'PlanController@params')->name('plans.params');

        // 需要检查权限的路由组
        Route::middleware('check.permission')->group(function () {
            // 上传文件
            Route::post('upload', 'UploadController@store')->name('upload.store');

            // 后台首页
            Route::get('/', 'HomeController@index')->name('home.index');
            // 登录日志
            Route::get('logs', 'LogController@index')->name('logs.index');

            // 用户管理
            Route::get('users', 'UserController@index')->name('users.index');
            Route::get('users/{user}', 'UserController@show')->name('users.show')->where(['user' => '[0-9]+']);
            Route::get('users/info', 'UserController@info')->name('users.info');
            Route::post('users', 'UserController@store')->name('users.store');
            Route::put('users/{user}', 'UserController@update')->name('users.update');
            Route::delete('users/{user}', 'UserController@delete')->name('users.destroy');
            Route::post('users/avatar', 'UserController@avatar')->name('users.avatar');
            Route::post('users/profile', 'UserController@profile')->name('users.profile');
            Route::patch('users/{user}/status', 'UserController@status')->name('users.status');

            // 角色管理
            Route::resource('roles', 'RoleController')->except(['create', 'edit']);
            Route::get('roles/{role}', 'RoleController@show')->name('roles.show')->where(['role' => '[0-9]+']);
            Route::post('roles/{role}/permissions', 'RoleController@permissions')->name('roles.permissions');
            Route::post('roles/{role}/menus', 'RoleController@menus')->name('roles.menus');

            // 权限管理
            Route::resource('permissions', 'PermissionController')->except(['create', 'edit']);
            Route::get('permissions/{permission}', 'PermissionController@show')->name('permissions.show')->where(['permission' => '[0-9]+']);

            // 菜单管理
            Route::resource('menus', 'MenuController')->except(['create', 'edit']);
            Route::get('menus/{menu}', 'MenuController@show')->name('menus.show')->where(['menu' => '[0-9]+']);

            // 拍摄管理
            Route::resource('plans', 'PlanController')->except(['create', 'edit']);
            Route::get('plans/{plan}', 'PlanController@show')->name('plans.show')->where(['plan' => '[0-9]+']);
            Route::post('plans/{plan}/photos', 'PhotoController@store')->name('photos.store');
            Route::post('plans/{plan}/photos/{photo}/retouch', 'PhotoController@retouch')->name('photos.retouch');
            Route::patch('plans/{plan}/photos/{photo}/retouch', 'PhotoController@update')->name('photos.update');
            Route::patch('plans/{plan}/photos/{photo}/comments', 'PhotoController@comments')->name('photos.comments');
            Route::patch('plans/{plan}/photos/{photo}/toggle', 'PhotoController@toggle')->name('photos.toggle');
            Route::delete('plans/{plan}/photos/{photo}', 'PhotoController@destroy')->name('photos.destroy');

            // 配置管理
            Route::resource('settings', 'SettingController')->except(['create', 'edit']);
            Route::get('settings/{setting}', 'SettingController@show')->name('settings.show')->where(['setting' => '[0-9]+']);
        });

    });

});
